package server.gameplay;

import java.nio.channels.SocketChannel;

import network.protocol.PlayerPackage;

/**
 * @author Erik
 * An extension to PlayerPackage. The server shall know more than the clients
 */
@SuppressWarnings("serial")
public class ServerPlayerPackage extends PlayerPackage{
	private boolean admin;
	private SocketChannel socket;
	
	public ServerPlayerPackage(int id, String nickname){
		super(id, nickname);
	}
	
	public boolean hasGrowth() {
		return getTotalPop() < getSupportedPopulation();
	}
	
	public boolean equal(ServerPlayerPackage p){
		return p.getID() == getID();
	}
	
	public ServerPlayerPackage(SocketChannel socket, int id) {
		super(id, "player");
		this.socket = socket;
	}
	
	public ServerPlayerPackage(int id, String nickname, double morale, double speed, int totalPop, int totalArmory) {
		super(id, nickname, morale, speed, totalPop, totalArmory);
	}
	
	public ServerPlayerPackage(String data){
		super(data);
	}
	
	public void setTotalPop(int totalPop){
		super.setTotalPop(totalPop);
	}
	
	public void setNickName(String nickName) {
		if (admin)
			super.setNickName( "[Admin]" + nickName);
		else
			super.setNickName(nickName);
	}
	
	public void setTotalArmorys (int n) {
		if (n < 5)
			super.setTotalArmorys(n);
		else
			super.setTotalArmorys(4);
	}
	
	public SocketChannel getSocket() {
		return socket;
	}
	
	public void setAdmin(boolean state) {
		admin = state;
	}

	public boolean isAdmin() {
		return admin;
	}

}
